package 力扣;

import java.util.Observable;

/**
 * @author yyq
 * @create 2022-06-16 8:57
 */
public class leetcode63 {
    public static void main(String[] args) {
        leetcode63 l=new leetcode63();
        l.uniquePathsWithObstacles(new int[][]{{0,0,0},{0,1,0},{0,0,0}});
    }
    public int uniquePathsWithObstacles(int[][] obstacleGrid){
        if(obstacleGrid[0][0]==1) return 0;
        int m=obstacleGrid.length;
        int n =obstacleGrid[0].length;
        int[][] dp=obstacleGrid;
        dp[0][0] = 1;
        int flag = 1;
        for (int i=1;i< dp.length;i++){

            if(dp[i][0]==1) {
                dp[i][0]=0;
                flag = 0;
            }
            else dp[i][0] = flag;
        }
        flag = 1;
        for (int j=1;j<dp[0].length;j++){
            if(dp[0][j]==1) {
                dp[0][j]=0;
                flag = 0;
            }
            else dp[0][j] = flag;
        }
        for (int i=1;i<dp.length;i++){
            for (int j = 1;j<dp[0].length;j++){
                if(dp[i][j]==0)
                    dp[i][j] = dp[i-1][j] + dp[i][j-1];
                else if(dp[i][j]==1) dp[i][j]=0;
            }
        }

        return dp[m-1][n-1];
    }
}
